# Makefile for the Sabertooth package. Run as:
#	make - Compile all files into an executable called sabertooth.
#	make clean - Delete the executable and all object files.
#	make clean_obj - Delete all object files.
#
# Last edited by: Timothy Flynn (trflynn@wpi.edu)
# Version: April 8, 2011

URG_SRC_DIR = include/urg-0.8.11
SRC_DIR = src
INCLUDE_DIR = include
BUILD_DIR = build
BIN_DIR = bin

URG_INCLUDE = -I$(URG_SRC_DIR)/common \
	-I$(URG_SRC_DIR)/connection \
	-I$(URG_SRC_DIR)/coordinate \
	-I$(URG_SRC_DIR)/geometry \
	-I$(URG_SRC_DIR)/monitor \
	-I$(URG_SRC_DIR)/system \
	-I$(URG_SRC_DIR)/urg \
	-I$(URG_SRC_DIR)/connection/sdl \
	-I/usr/include \
	-I/usr/include/SDL

INCLUDE = -I$(INCLUDE_DIR)

URG_OBJ = $(URG_SRC_DIR)/common/*.o \
	$(URG_SRC_DIR)/connection/*.o \
	$(URG_SRC_DIR)/coordinate/*.o \
	$(URG_SRC_DIR)/geometry/*.o \
	$(URG_SRC_DIR)/system/*.o \
	$(URG_SRC_DIR)/urg/*.o \
	$(URG_SRC_DIR)/connection/sdl/*.o

LIB = -lSDL_net -lpthread -lrt

CFLAGS = -g

LIDAR_OBJ = $(BUILD_DIR)/lidar.o

GAIT_OBJ = $(BUILD_DIR)/CommunicationMan.o \
	$(BUILD_DIR)/Gait.o \
	$(BUILD_DIR)/Leg.o \
	$(BUILD_DIR)/Link.o \
	$(BUILD_DIR)/Matrix.o \
	$(BUILD_DIR)/Robot.o \
	$(BUILD_DIR)/Timer.o \
	$(BUILD_DIR)/XYController.o

executive: $(LIDAR_OBJ) $(GAIT_OBJ) $(BUILD_DIR)/Executive.o
	g++ -Wall $(CFLAGS) $(LIDAR_OBJ) $(GAIT_OBJ) $(URG_OBJ) $(BUILD_DIR)/Executive.o $(LIB) -o $(BIN_DIR)/sabertooth
	@echo

$(BUILD_DIR)/Executive.o: $(SRC_DIR)/Executive.cpp
	g++ -Wall -c $(CFLAGS) $(SRC_DIR)/Executive.cpp $(INCLUDE) $(URG_INCLUDE) -o $(BUILD_DIR)/Executive.o
	@echo

$(BUILD_DIR)/lidar.o: $(SRC_DIR)/lidar/lidar.cpp
	g++ -Wall -c $(CFLAGS) $(SRC_DIR)/lidar/lidar.cpp $(INCLUDE) $(URG_INCLUDE) -o $(BUILD_DIR)/lidar.o
	@echo

$(BUILD_DIR)/CommunicationMan.o: $(SRC_DIR)/motion/CommunicationMan.cpp $(INCLUDE_DIR)/motion/CommunicationMan.h
	g++ -Wall -c $(CFLAGS) $(SRC_DIR)/motion/CommunicationMan.cpp $(INCLUDE) -o $(BUILD_DIR)/CommunicationMan.o
	@echo

$(BUILD_DIR)/Gait.o: $(SRC_DIR)/motion/Gait.cpp $(INCLUDE_DIR)/motion/Gait.h
	g++ -Wall -c $(CFLAGS) $(SRC_DIR)/motion/Gait.cpp $(INCLUDE) -o $(BUILD_DIR)/Gait.o
	@echo

$(BUILD_DIR)/Leg.o: $(SRC_DIR)/motion/Leg.cpp $(INCLUDE_DIR)/motion/Leg.h
	g++ -Wall -c $(CFLAGS) $(SRC_DIR)/motion/Leg.cpp $(INCLUDE) -o $(BUILD_DIR)/Leg.o
	@echo

$(BUILD_DIR)/Link.o: $(SRC_DIR)/motion/Link.cpp $(INCLUDE_DIR)/motion/Link.h
	g++ -Wall -c $(CFLAGS) $(SRC_DIR)/motion/Link.cpp $(INCLUDE) -o $(BUILD_DIR)/Link.o
	@echo

$(BUILD_DIR)/Matrix.o: $(SRC_DIR)/motion/Matrix.cpp $(INCLUDE_DIR)/motion/Matrix.h
	g++ -Wall -c $(CFLAGS) $(SRC_DIR)/motion/Matrix.cpp $(INCLUDE) -o $(BUILD_DIR)/Matrix.o
	@echo

$(BUILD_DIR)/Robot.o: $(SRC_DIR)/motion/Robot.cpp $(INCLUDE_DIR)/motion/Robot.h
	g++ -Wall -c $(CFLAGS) $(SRC_DIR)/motion/Robot.cpp $(INCLUDE) -o $(BUILD_DIR)/Robot.o
	@echo

$(BUILD_DIR)/Sabertooth.o: $(SRC_DIR)/motion/Sabertooth.cpp
	g++ -Wall -c $(CFLAGS) $(SRC_DIR)/motion/Sabertooth.cpp $(INCLUDE) -o $(BUILD_DIR)/Sabertooth.o
	@echo

$(BUILD_DIR)/Timer.o: $(SRC_DIR)/motion/Timer.cpp $(INCLUDE_DIR)/motion/Timer.h
	g++ -Wall -c $(CFLAGS) $(SRC_DIR)/motion/Timer.cpp $(INCLUDE) -o $(BUILD_DIR)/Timer.o
	@echo

$(BUILD_DIR)/XYController.o: $(SRC_DIR)/motion/XYController.cpp $(INCLUDE_DIR)/motion/XYController.h
	g++ -Wall -c $(CFLAGS) $(SRC_DIR)/motion/XYController.cpp $(INCLUDE) -o $(BUILD_DIR)/XYController.o
	@echo

clean:
	rm -f $(BUILD_DIR)/*.o $(BIN_DIR)/* logDesiredPositions.txt logIK.txt

clean_obj:
	rm -f $(BUILD_DIR)/*.o logDesiredPositions.txt logIK.txt
	
